#include "Linkedlist.h"
#include <iostream>
using namespace std;

int main()
{
    int sizeA, sizeB;
    LinkedList<int> *lA = new LinkedList<int>;
    LinkedList<int> *lB = new LinkedList<int>;

    cin >> sizeA;
    for (int i = 0; i < sizeA; i++)
    {
        int temp_num = 0;
        cin >> temp_num;
        lA->push(temp_num);
    }

    cin >> sizeB;
    for (int i = 0; i < sizeB; i++)
    {
        int temp_num, temp_flag;
        cin >> temp_num >> temp_flag;
        lB->push(temp_num, temp_flag);
    }

    Node<int> *currentB = lB->head;
    while (currentB)
    {
        if (currentB->flag == 0)
        {
            lA->delete_(currentB->data);
        }
        else if (currentB->flag == 1)
        {
            lA->insert(currentB->data);
        }
        currentB = currentB->next;
    }

    lA->print();
    return 0;
}